import { BaseItem } from "../common/BaseItem";
import { CDItemData } from "../../cache/CDItem/CDItemData";
import { SWFPlayer } from "../../scene/modle/SWFPlayer";
import { ModelType } from "../../scene/modle/data/ModelType";
import { SystemSetter } from "../system/SystemSetter";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { CareerUtil } from "../common/util/CareerUtil";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { SkillInfo } from "../../model/SkillInfo";
import { Cache } from "../../cache/Cache";
import { SkillConfig } from "../../resource/SkillConfig";
import { ESkillUseType } from "../../../../Message/Public/ESkillUseType";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ItemData } from "../../resource/info/ItemData";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { PetInfo } from "../../resource/info/PetInfo";
import { PetCoolDownInfo } from "../pet/PetCoolDownInfo";
import { ToolTipsManager } from "../../../../com/mui/manager/ToolTipsManager";
import { SkillsUtil } from "../../scene/skill/SkillsUtil";
import { PetUtil } from "../pet/info/PetUtil";
import { DragManager } from "../../../../com/mui/manager/DragManager";
type int = number;
//class ShortcutsItem
    
    export  class ShortcutsItem extends BaseItem
    {
        constructor(arg1: int=0)
        {
            super();
            this.isShowCdLeftTime = true;
            _bitmap.x = 3;
            _bitmap.y = 3;
            this._pos = arg1;
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            this.buttonMode = true;
            this.useHandCursor = true;
            return;
        }

        public doPublicCd(arg1: CDItemData): void
        {
            if (arg1) 
            {
                freezingEffect.cdTime = arg1;
                arg1.startCoolDown();
            }
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._lineBox.visible = true;
            return;
        }

        /* internal  */onMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._lineBox.visible = false;
            return;
        }

        public ShortcutsItem.get isShowBg(): Boolean
        {
            return this._isShowBg;
        }

        public set isShowBg(arg1: Boolean)
        {
            this._isShowBg = arg1;
            this._skillBg.visible = arg1;
            return;
        }

        /* internal  */addCanNotAttackMask(): void
        {
            if (!this._bmpCanNotUse) 
            {
                this._bmpCanNotUse = new Object /* flash.display.Bitmap */();
                this._bmpCanNotUse.x = 3;
                this._bmpCanNotUse.y = 3;
                this._bmpCanNotUse.bitmapData = bmpdCanNotUse;
            }
            this.addChild(this._bmpCanNotUse);
            return;
        }

        public ShortcutsItem.get isUsing(): Boolean
        {
            return this._isUsing;
        }

        public set isUsing(arg1: Boolean)
        {
            this._isUsing = arg1;
            if (arg1) 
            {
                if (this._effectPlayer == null) 
                {
                    this._effectPlayer = new SWFPlayer();
                }
                this._effectPlayer.load("SkillUsing.swf", ModelType.NormalSwf, null);
                this._effectPlayer.move(18, 18);
                if (this.contains(this._effectPlayer) == false) 
                {
                    this.addChild(this._effectPlayer);
                }
            }
            else if (this._effectPlayer && this.contains(this._effectPlayer)) 
            {
                this.removeChild(this._effectPlayer);
            }
            return;
        }

        public setCdTime(arg1: CDItemData): void
        {
            freezingEffect.cdTime = arg1;
            if (SystemSetter.currentSetter.showSkillCdTime) 
            {
                leftTimeCd.cdTime = arg1;
            }
            return;
        }

        public clearCd(): void
        {
            freezingEffect.clearEffect();
            leftTimeCd.clearLeftTime();
            return;
        }

        public removeMouseOverOutListener(): void
        {
            this.removeEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            this.removeEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            return;
        }

        public static get bmpdCanNotUse(): Object /* flash.display.BitmapData */
        {
            if (!ShortcutsItem._bmpdCanNotUse) 
            {
                ShortcutsItem._bmpdCanNotUse = new Object /* flash.display.BitmapData */(32, 32);
                ShortcutsItem._bmpdCanNotUse.fillRect(new Object /* flash.geom.Rectangle */(0, 0, 32, 32), 2566914048);
            }
            return ShortcutsItem._bmpdCanNotUse;
        }

        /* internal  */removeCanNotAttackMask(): void
        {
            if (this._bmpCanNotUse && contains(this._bmpCanNotUse)) 
            {
                removeChild(this._bmpCanNotUse);
            }
            return;
        }

        public /* override */ setSize(arg1: number, arg2: number): void
        {
            super.setSize(arg1, arg2);
            if (freezingEffect) 
            {
                freezingEffect.x = 19;
                freezingEffect.y = 19;
            }
            return;
        }

        public setFreezingEffectPoint(arg1: int, arg2: int): void
        {
            freezingEffect.x = arg1;
            freezingEffect.y = arg2;
            return;
        }

        public /* override */ get bitmapdata(): Object /* flash.display.BitmapData */
        {
            return super.bitmapdata;
        }

        protected /* override */ createChildren(): void
        {
            this._width = 38;
            this._height = 38;
            this._skillBg = GlobalClass.getBitmap(ImagesConst.NavskillBg);
            this.addChild(this._skillBg);
            super.createChildren();
            this.setSize(38, 38);
            freezingEffect.setMaskSize(32, 32);
            this.indexLabel = ObjCreate.createTextField("", 2, 0, 20, 20, this, new GTextFormat(FontUtil.songtiName, 11, 16777215));
            this.indexLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._iconTxt = ObjCreate.createTextField("", 20, 20, 20, 20, this);
            this._iconTxt.mouseEnabled = false;
            this._iconTxt.textColor = CareerUtil.getSkillColor();
            this._lineBox = new Object /* flash.display.Sprite */();
            this._lineBox.visible = false;
            this.addChild(this._lineBox);
            this._lineBox.graphics.lineStyle(1, 65280, 1);
            this._lineBox.graphics.drawRoundRect(1, 1, 35, 35, 4, 4);
            this._lineBox.graphics.endFill();
            this._lineBox.filters = [FilterConst.colorGlowFilter(65280)];
            return;
        }

        public set canUseSkill(arg1: Boolean)
        {
            this._bmpCanNotUse.visible = arg1;
            return;
        }

        public ShortcutsItem.get pos(): int
        {
            return this._pos;
        }

        public ShortcutsItem.get itemName(): string
        {
            return this._itemName;
        }

        public IndexLabelTxt(arg1: int): void
        {
            this.indexLabel.htmlText = "<font color=\'#ffffff\'>" + arg1 + "</font>";
            return;
        }

        public setLabelTxt(arg1: string): void
        {
            this.indexLabel.htmlText = "<font color=\'#ffffff\'>" + arg1 + "</font>";
            return;
        }

        public /* override */ get dragSource(): Object
        {
            return this._dragSource;
        }

        public /* override */ set dragSource(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            this._dragSource = arg1;
            if (arg1) 
            {
                if (typeof arg1 === "skillinfo") 
                {
                    loc1 = arg1 as SkillInfo;
                    if (loc1.learned) 
                    {
                        this._itemName = loc1.skillName;
                        this.source = loc1.tSkill.skillIcon + ".jpg";
                        this.amountLabel.text = "";
                        if (loc3 = Cache.instance.timeCdCache.getSkillCd(loc1)) 
                        {
                            this.setCdTime(loc3);
                        }
                        else 
                        {
                            this.clearCd();
                        }
                        this.locked = false;
                    }
                    else 
                    {
                        this.detory();
                    }
                    loc2 = SkillConfig.instance.getIconType(loc1.skillCareer, loc1.position);
                    if (!(loc1.useType == ESkillUseType._ESkillUseTypeAuto) && loc2) 
                    {
                        this._iconTxt.htmlText = HTMLUtil.addColor(loc2.iconName, CareerUtil.getSkillColorString());
                        if (!contains(this._iconTxt)) 
                        {
                            addChild(this._iconTxt);
                        }
                    }
                    else if (contains(this._iconTxt)) 
                    {
                        removeChild(this._iconTxt);
                    }
                }
                else if (typeof arg1 === "itemdata") 
                {
                    this.itemData = arg1 as ItemData;
                    this._itemName = itemData.itemInfo.item.name;
                    if (loc4 = Cache.instance.timeCdCache.getCdTime(itemData)) 
                    {
                        this.setCdTime(loc4);
                    }
                    else 
                    {
                        this.clearCd();
                    }
                    this.locked = false;
                    if (contains(this._iconTxt)) 
                    {
                        removeChild(this._iconTxt);
                    }
                }
                else if (typeof arg1 === "spetinfo") 
                {
                    loc5 = arg1 as SPetInfo;
                    this.source = PetInfo.getPetAvatarUrl(loc5.changeCode);
                    loc7 = new PetCoolDownInfo(loc5.uid, loc5.status);
                    if ((loc6 = Cache.instance.timeCdCache.addPetCd(loc7)) && loc6.isCoolDown) 
                    {
                        this.setCdTime(loc6);
                    }
                    else 
                    {
                        this.clearCd();
                    }
                    this.amountLabel.text = "";
                    this.locked = false;
                    if (contains(this._iconTxt)) 
                    {
                        removeChild(this._iconTxt);
                    }
                }
                else 
                {
                    this._itemName = "";
                    this.clearCd();
                    if (contains(this._iconTxt)) 
                    {
                        removeChild(this._iconTxt);
                    }
                }
                ToolTipsManager.register(this);
            }
            else 
            {
                if (contains(this._iconTxt)) 
                {
                    removeChild(this._iconTxt);
                }
                this.clearCd();
                this.source = null;
                amountLabel.text = "";
                ToolTipsManager.unregister(this);
            }
            this.updateIsCanNotAttackMask();
            return;
        }

        public updateIsCanNotAttackMask(): void
        {
            var loc1=null;
            if (this._dragSource && this._dragSource is SkillInfo) 
            {
                loc1 = this._dragSource as SkillInfo;
                if (!SkillsUtil.instance.isCanControlUseSkill(loc1)) 
                {
                    this.addCanNotAttackMask();
                    return;
                }
            }
            this.removeCanNotAttackMask();
            return;
        }

        public set addCanNotAttackMaskValue(arg1: Boolean)
        {
            if (arg1) 
            {
                this.addCanNotAttackMask();
            }
            else 
            {
                this.removeCanNotAttackMask();
            }
            return;
        }

        protected /* override */ resetBitmapSize(): void
        {
            if (_bitmap) 
            {
                _bitmap.width = 32;
                _bitmap.height = 32;
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            return;
        }

        public /* override */ get toolTipData()
        {
            if (!isShowToolTip) 
            {
                return null;
            }
            var loc1=this.dragSource;
            if (loc1) 
            {
                if (typeof loc1 === "skillinfo") 
                {
                    return (loc1 as SkillInfo).getShortToolTips();
                }
                if (typeof loc1 === "itemdata") 
                {
                    return (loc1 as ItemData).getToolTipData();
                }
                if (typeof loc1 === "spetinfo") 
                {
                    return PetUtil.getShortcutsPetTooltipsData(loc1 as SPetInfo);
                }
            }
            return null;
        }

        public /* override */ get isDragAble(): Boolean
        {
            return _dragAble;
        }

        public /* override */ set isDragAble(arg1: Boolean)
        {
            _dragAble = arg1;
            return;
        }

        protected /* override */ onMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.isDragAble && this.dragSource) 
            {
                amountLabel.visible = false;
                DragManager.instance.startDragItem(this, this.bitmapdata);
                amountLabel.visible = true;
            }
            return;
        }

        public detory(): void
        {
            this.clearCd();
            this.dragSource = null;
            this.itemData = null;
            this.amountLabel.text = "";
            this._iconTxt.text = "";
            return;
        }

        public /* override */ set amount(arg1: int)
        {
            _amount = arg1;
            if (_amount >= 0) 
            {
                if (typeof this.dragSource === "itemdata") 
                {
                    amountLabel.text = _amount.toString();
                }
                else 
                {
                    amountLabel.text = "";
                }
            }
            else 
            {
                amountLabel.text = "";
            }
            return;
        }

        public doCoolDown(arg1: CDItemData, arg2: Boolean=false): void
        {
            if (arg1) 
            {
                this.setCdTime(arg1);
                if (arg2) 
                {
                    arg1.startCoolDown();
                }
            }
            return;
        }

        /* internal */ /* var */_pos: int;

        /* internal */ /* var */_dragSource: Object;

        /* internal */ /* var */indexLabel: Object /* flash.text.TextField */;

        /* internal */ /* var */_effectPlayer: SWFPlayer;

        /* internal */ /* var */_itemName: string;

        /* internal */ /* var */_lineBox: Object /* flash.display.Sprite */;

        /* internal */ /* var */_isShowBg: Boolean;

        /* internal */ /* var */_isUsing: Boolean;

        /* internal */ /* var */_iconTxt: Object /* flash.text.TextField */;

        protected /* var */_bmpCanNotUse: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_skillBg: Object /* flash.display.Bitmap */;

        /* internal */ static /* var */_bmpdCanNotUse: Object /* flash.display.BitmapData */;
    }
